﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UTSDAL.LINQSQL.Model;
using UTSDAL.LINQSQL.Helper;
using UTSDAL.LINQSQL.DAO;
using UTSDAL.LINQSQL.Exceptions;

namespace UTSDAL.LINQSQL
{
    public class ConstraintValidators
    {

        private static UTSDataContext context = DataContextHelper.Context;

        private static ParameterDAO parameterDAO = new ParameterDAO();

        public static void validate(TimetableEvent timetableEvent)
        {
            validateMaximumAllowedTime(timetableEvent);

        }

        private static TimetableEventDAO timetableEventDAO = new TimetableEventDAO();

        public static void validateMaximumAllowedTime(TimetableEvent timetableEvent)
        {
            int duration = timetableEventDAO.getTimetableEventsDurationForCohortForCourseDay(timetableEvent.Cohort,timetableEvent.CourseDay);

            duration += (timetableEvent.EndTime.Subtract(timetableEvent.StartTime)).Hours;

            int maxAllowedTimePerCohortPerDay = Convert.ToInt32(parameterDAO.findParameterValue("MaxAllowedTimePerCohortPerDay"));


            if (duration > maxAllowedTimePerCohortPerDay)
            {
                throw new ExceedingMatchingTimeException("Cohort Time Per Day has exceeded");
            }
        }

    }
}
